package com.ktgj.other.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.other.domain.RcTrain;
import com.ktgj.other.service.IRcTrainService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 专车火车站Controller
 * 
 * @author ruoyi
 * @date 2022-07-27
 */
@RestController
@RequestMapping("/train")
public class RcTrainController extends BaseController
{
    @Autowired
    private IRcTrainService rcTrainService;

    /**
     * 查询专车火车站列表
     */
    @PreAuthorize(hasPermi = "other:train:list")
    @GetMapping("/list")
    public TableDataInfo list(RcTrain rcTrain)
    {
        startPage();
        List<RcTrain> list = rcTrainService.selectRcTrainList(rcTrain);
        return getDataTable(list);
    }

    /**
     * 导出专车火车站列表
     */
    @PreAuthorize(hasPermi = "other:train:export")
    @Log(title = "专车火车站", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RcTrain rcTrain) throws IOException
    {
        List<RcTrain> list = rcTrainService.selectRcTrainList(rcTrain);
        ExcelUtil<RcTrain> util = new ExcelUtil<RcTrain>(RcTrain.class);
        util.exportExcel(response, list, "专车火车站数据");
    }

    /**
     * 获取专车火车站详细信息
     */
    @PreAuthorize(hasPermi = "other:train:query")
    @GetMapping(value = "/{traincode}")
    public AjaxResult getInfo(@PathVariable("traincode") String traincode)
    {
        return AjaxResult.success(rcTrainService.selectRcTrainById(traincode));
    }

    /**
     * 新增专车火车站
     */
    @PreAuthorize(hasPermi = "other:train:add")
    @Log(title = "专车火车站", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RcTrain rcTrain)
    {
        return toAjax(rcTrainService.insertRcTrain(rcTrain));
    }

    /**
     * 修改专车火车站
     */
    @PreAuthorize(hasPermi = "other:train:edit")
    @Log(title = "专车火车站", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RcTrain rcTrain)
    {
        return toAjax(rcTrainService.updateRcTrain(rcTrain));
    }

    /**
     * 删除专车火车站
     */
    @PreAuthorize(hasPermi = "other:train:remove")
    @Log(title = "专车火车站", businessType = BusinessType.DELETE)
	@DeleteMapping("/{traincodes}")
    public AjaxResult remove(@PathVariable String[] traincodes)
    {
        return toAjax(rcTrainService.deleteRcTrainByIds(traincodes));
    }
}
